$(function () {
    $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green-login"});
    $('.imgcode').click(function () {
        var url = "/captcha/captchaImage?type=" + "math" + "&s=" + Math.random();
        $(".imgcode").attr("src", url);
    });
});

// 登录
$("#btnSubmit").click(function () {
    login();
});
function keyLogin() {
    if (event.keyCode == 13) {
        login();
    }
}
function login() {
    var username = $.common.trim($("input[name='username']").val());
    var password = $.common.trim($("input[name='password']").val());
    var validateCode = $("input[name='validateCode']").val();
    var rememberMe = $("input[name='rememberme']").is(':checked');
    console.log(username + password + validateCode + rememberMe);
    $.ajax({
        type: "post",
        url: "/login",
        data: {
            "username": username,
            "password": password,
            "validateCode": validateCode,
            "rememberMe": rememberMe
        },
        success: function (r) {
            console.log(r);
            if (r.code == 0) {
                location.href = '/index';
            } else {
                // $.modal.closeLoading();
                $('.imgcode').click();
                $.modal.msg(r.msg);
            }
        }
    });
}


